package aad.storyboard.view;

import aad.storyboard.R;
import aad.storyboard.controller.NavigationClickListener;
import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.ViewFlipper;

/**
 * Adapter pattern
 * Enables clickable links in the ClickableScriptView and in the WikiView 
 */
public class JavaScriptInterface {
	
	 
	 static Activity activity;	 
	 WikiView wikiView;		 
	 private static Handler mHandler=new Handler();

	    /** Instantiate the interface and set the context */
	    public JavaScriptInterface(Activity a, WikiView view, ViewFlipper flip)
	    {
	       activity=a;
	       wikiView=view;	
	       
	        
	    }

	    public JavaScriptInterface(Activity activity, WikiView wikiView) {
	    	 this. activity=activity;
		     this.wikiView=wikiView;
		}

		public void showExplanation(String word)
	    {   
			String file="file:///android_asset/"+word+".html";   	 
			wikiView=(WikiView)activity.findViewById(R.id.wikiView);
			wikiView.loadUrl(file);			
			   
	        mHandler.removeCallbacks(mTransitionTask);	    	
		    mHandler.postDelayed(mTransitionTask, 100);		    
	        	    	
	    
	    }
	    
	    private static Runnable mTransitionTask = new Runnable() {
			   @Override
			public void run() {	
				   System.out.println("Java script triggered");
				   
			   }
			};
		



}
